<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" ><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" >
<head>
<title>ChelleWeb TAAK</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />

<link rel="stylesheet" href="css/screen.css" type="text/css" />
<?php
echo $_SESSION['id'];
/*session_start();
if($_SESSION['myusername'] != "secretword") {
echo $_SESSION['myusername'];
echo "no way dude";
}*/
$check = TRUE;
include('/PHP/database.php');
$db = new db();

/* POPULATE KLAS DROPDOWN ON LOAD */
$contRAWklas = $db->get_klas();
$contKlas = "";
while ($row = mysql_fetch_assoc($contRAWklas)) {
	if(isset($_SESSION["klaskeuze"]) && $_SESSION["klaskeuze"] == $row["gid"]){
		$contKlas .= '<option value="' . $row["gid"] . '" selected="selected">' . $row["gname"] . '</option>';
	}else{
		$contKlas .= '<option value="' . $row["gid"] . '">' . $row["gname"] . '</option>';
	}
}

/* KIES KLAS IS CLICKED */
if(isset($_POST["kiesklas"]) || isset($_POST["kiestaak"])) {
	$_SESSION["klaskeuze"] = $_POST["klaslijst"];
	$_SESSION["taakkeuze"] = $_POST["taaklijst"]; 
	$contRAW = $db->get_taken($_POST["klaslijst"]);
	$contTaken = '<td>Taak:</td><td><select name="taaklijst">';
		while ($row = mysql_fetch_assoc($contRAW)) {
			if($_SESSION["taakkeuze"] == $row["tid"]){
				$contTaken .= '<option value="' . $row["tid"] . '" selected="selected">' . $row["tname"] . '</option>';
			}else{
    			$contTaken .= '<option value="' . $row["tid"] . '">' . $row["tname"] . '</option>';
			}
		}
		$contTaken .= '</select><input type="submit" name="kiestaak" value="Kies Taak" /><input type="submit" name="nieuwtaak" value="Nieuwe Taak" /></td>';
}
/* KIESTAAK GETS TAAK DATA */
if(isset($_POST["kiestaak"]))  { 
	$_SESSION["taakkeuze"] = $_POST["taaklijst"]; 
	if($_POST["taaklijst"]){
		$contRAWtask = $db->get_task($_POST["taaklijst"], $_POST["klaslijst"]);
		$contTask = "";
		while ($row = mysql_fetch_assoc($contRAWtask)) {
    		$contTask .= '<p><input name="opgave" type="text" value="' . $row["opgave"] . '" size="50"/><input name="oplossing_0" type="text" value="' . $row["oplossing"] . '" size="18" /></p>';
		}
	} else {
		$check = FALSE;
		$msg = "Gelieve een Klas en Taak in te vullen";
	}
}
/*NIEUWTAAK IS CLICKED */
if(isset($_POST["nieuwtaak"])){
	$contTaken = '<td>Taak:</td><td><input name="taaklijst" type="text" size="20" /></td><td><input type="submit" name="maaktaak" value= "Maak Taak" /></td>';
}
/* SET DATA IS CLICKED */
if(isset($_POST["set"]) || isset($_POST["maaktaak"])) {
	if(isset($_POST["klaslijst"]) && isset($_POST["taaklijst"])){
		$msg = $db->set_task($_POST["link"], $_POST["invul"]);
	} else {
		$msg = "gelieve een klas en taak te specifiëren";
	}
}
?>
<script src="JS/jquery.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
var count = $('#nameFields p').size() + 1;
	jQuery(document).ready(function(){
		jQuery("#addField").click( function() {
			var text = '<p><input name="opgave_' + count + '" type="text" value="<?php print($opgave);?>" size="50"/><input name="oplossing_' + count + '" type="text" value="<?php print($oplossing);?>" size="18" /></p>';
			jQuery("#nameFields").append(text);
			count++;
		});
	});
</script>
</head>
<body>
<div id="main" >
<div id="banner" >
<h1>ChelleWeb 4 teh WINzor</h1>
</div>
<div id="border">
<div id="left">
			<ul>
			<li><a href="index.php?link=home">Home</a></li> 
			<li><a href="index.php?link=tips">Tips</a></li>
			<li><a href="index.php?link=Vragen">Vragen</a></li>
			<li><a href="index.php?link=contact">Contact</a></li>
			<li><a href="admin.php">Admin</a>
				<ul>
					<li><a href="admin.php">Teksten</a></li>
                    <li><a href="klas.php">Klassen</a></li>
					<li><a href="taak.php">Taken</a></li>
				</ul>
			</li>
            <li><a href="users.php">Gebruikers</a>
				<ul>
					<li><a href="/PHP/users.php">Lijsten</a></li>
					<li><a href="/PHP/logoff.php">Uitloggen</a></li>
				</ul>
			</li>
		</ul>
	</div>
<div id="content" > 
	<div id="right">
	</div>
		<div id="text">
        <h2>Administration Page - use with care</h2>
		<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
			<table>
				<tr>
                	<td>Klas:</td>
					<td><select name="klaslijst"><?php echo $contKlas; ?></select><input type="submit" name="kiesklas" value="Kies Klas" /></td>
				</tr>
				<tr>
					<?php
						echo $contTaken;
					?>
				</tr>
            </table>
            <table>
            	<tr>
					<th>Opgave:</th>
                    <th>Oplossing:</th>
                </tr>
			</table>
			<div id="nameFields">
			<?php
                if(isset($_POST["kiestaak"])){
					echo $contTask;
				}else{
			?>
                <p>		
					<input name="opgave_0" type="text" value="<?php print($opgave);?>" size="50"/><input name="oplossing_0" type="text" value="<?php print($oplossing);?>" size="18" />
				</p>
             <?php
				}
			 ?>
			</div>
			<input type="submit" name="set" value="Set Data" />
			<input type="checkbox" name="error" value="error" /> Error reporting
			<a href="#" onclick="return false;" id="addField">Opgave Toevoegen</a>
		</form>
		<div id="msg">
		<?php echo $msg; ?>
		</div>
		</div>
</div>
<div id="footer">
	<ul>
		<li><a href="admin.php">admin</a> &#149 </li> 
		<li><a href="index.php?link=pr">pr</a> &#149 </li>
		<li><a href="index.php?link=marketing">marketing</a> &#149</li>
		<li><a href="index.php?link=eventman">event management</a></li>
	</ul>
</div>
</div>
</div>
<?php
if (isset($_POST["error"]) && $check){
	$err = $db->error();
	echo $err;
}
?>
</body>
</html>